package com.knife.example;

import com.alibaba.fastjson.JSONObject;
import com.knife.entity.Z_DOMG;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

/**
 * create by yongli on 2022-02-10 11:25
 */

public class ZdomgFileWrite {
    public static void main(String[] args) {
        File file = new File("/Users/yongli/Desktop/lib.xlsx");
        String data="...";

        try {
            Workbook workbook = new HSSFWorkbook();
            Sheet sheet =workbook.createSheet("物料表");
            List<Z_DOMG> list = JSONObject.parseArray(data, Z_DOMG.class);
            for (int i = 0; i < list.size(); i++) {
                Row row = sheet.createRow(i);
                Z_DOMG z_domg = list.get(i);
                String matnr = z_domg.getMATNR();
                String lgort = z_domg.getLGORT();
                String werks = z_domg.getWERKS();

                row.createCell(0).setCellValue(werks);
                row.createCell(1).setCellValue(lgort);
                row.createCell(2).setCellValue(matnr);
            }
            workbook.write(new FileOutputStream(file));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
